#include <iostream>
#include <vector>

using namespace std;

struct TreeNode
{
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x)
        :val(x)
        , left(nullptr)
        , right(nullptr)
    {}
    TreeNode(int x, TreeNode* l, TreeNode* r)
        :val(x)
        , left(l)
        , right(r)
    {}
};
class Solution
{
public:
    void inorder(TreeNode* root, vector<int>& v)
    {
        if (!root)
        {
            return;
        }
        inorder(root->left, v);
        inorder(root->right, v);
        v.emplace_back(root->val);

    }
    vector<int> postorderTraversal(TreeNode* root)
    {
        vector<int> v;
        inorder(root, v);
        return v;
    }
};

int main()
{
    TreeNode* B = new TreeNode(3);
    TreeNode* A = new TreeNode(2, B, nullptr);
    TreeNode* root = new TreeNode(1, nullptr, A);

    Solution xz;
    vector<int> v = xz.postorderTraversal(root);
    for (auto e : v)
    {
        cout << e << " ";
    }

    return 0;
}